﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.7/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="lib/icheck/icheck.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>字典管理</title>
</head>
<body>
    <!--top 导航-->
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 角色管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>

    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <span class="select-box">
                    <select name="SelectType" id="SelectType" class="select">
                        <option value="0">请选择字典类型</option>
                        <option value="1">2-3环</option>
                        <option value="2">3-4环</option>
                        <option value="3">4-5环</option>
                        <option value="4">5-6环</option>
                        <option value="5">6环外</option>
                    </select>
                </span>
            </span>
            <span class="l">
                <a class="btn btn-primary radius" onclick="admin_add('添加字典', 'addDictionary.html', '600', '300')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i>添加字典</a>
                <button name="searchDic" id="searchDic" onclick="searchDic()" class="btn btn-success" type="button"><i class="Hui-iconfont">&#xe665;</i> 查询</button>
            </span>
            <span class="r">当前数据：<strong id="DicCount">0</strong> 条</span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg">
                <thead>
                    <tr class="text-c">
                        <th width="40">字典编号</th>
                        <th width="150">字典名称</th>
                        <th width="90">字典类型</th>
                        <th width="100">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="text-c">
                        <td>10001</td>
                        <td>住宅</td>
                        <td>1</td>
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="admin_edit('字典编辑', 'addDictionary.html', '1', '800', '500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a title="删除" href="javascript:;" onclick="admin_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                    <tr class="text-c">
                        <td>10002</td>
                        <td>非住宅</td>
                        <td>1</td>
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="admin_edit('管理员编辑', 'addDictionary.html', '1', '800', '500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a title="删除" href="javascript:;" onclick="admin_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                    <tr class="text-c">
                        <td>20001</td>
                        <td>便捷</td>
                        <td>2</td>
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="admin_edit('管理员编辑', 'addDictionary.html', '1', '800', '500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a title="删除" href="javascript:;" onclick="admin_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                    <tr class="text-c">
                        <td>20002</td>
                        <td>比较便捷</td>
                        <td>2</td>
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="admin_edit('管理员编辑', 'addDictionary.html', '1', '800', '500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a title="删除" href="javascript:;" onclick="admin_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <!--模态框-->
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--域名配置-->
    <script type="text/javascript" src="static/WebApi.js"></script>
    <script type="text/javascript">

        var dicType = new Array();

        //获取字典类型储存在dicType中
        function getDicType() {
            $.ajax({
                type: "post",
                url: ApiUrl + "api/Dictionary/GetSelectType",
                data: {},
                async: false,
                success: function (data, resurt) {
                    $(data).each(function () {
                        dicType[this.value] = this.text;
                    })

                },
                error: function (e) {
                    parent.layer.msg('网络链接超时...!', { icon: 2, time: 1000 });
                }
            });

        };
       
        //显示字典
        $(document).ready(function () {

            $.ajax({
                type: "post",
                url: ApiUrl + "api/Dictionary/GetSelectType",
                data: {},
                success: function (data, resurt) {
                    $("#SelectType").empty();
                    $(data).each(function (i, item) {
                        $("#SelectType").append('<option value="' + item.value + '">' + item.text + '</option>');
                    })
                },
                error: function (e) {
                    parent.layer.msg('网络链接超时...!', { icon: 2, time: 1000 });
                },
                complete: function () {

                }
            });
            getDicType();//获取字典类型储存在dicType中
            showDic(0);//获取全部字典信息
        })

        //获取根据类型id字典信息
        function showDic(Dmenuid) {


            $.ajax({
                type: "post",
                url: ApiUrl + "api/Dictionary/Select",
                data: { "": Dmenuid},
                success: function (data) {
                    $("tbody").empty();
                    $("#DicCount").text($(data).length);
                    $(data).each(function (i, item) {
                       var thisDmenuid = dicType[this.Dmenuid];
                        var html = ''
                                 + '<tr id='+this.Did+' class="text-c">'
                                 + '   <td>' + this.DictionaryID + '</td>'
                                 + '   <td>' +this.DictionaryName + '</td>'
                                 + '   <td>' + thisDmenuid + '</td>'
                                 + '   <td class="td-manage">'
                                 + '       <a title="编辑" href="javascript:;" onclick="admin_edit(\'管理员编辑\', \'updateDictionary.html\', \'' + this.Did + '\',\'800\', \'500\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>'
                                 + '       <a title="删除" href="javascript:;" onclick="admin_del(' + this.Did + ')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>'
                                 + '   </td>'
                                 + '</tr>';
                        $("tbody").append(html);
                    })
                },
                error: function (e) {
                    parent.layer.msg('网络链接超时...!', { icon: 2, time: 1000 });
                },
                complete: function () {

                }
            })
        };
        /*
            参数解释：
            title	标题
            url		请求的url
            id		需要操作的数据id
            w		弹出层宽度（缺省调默认值）
            h		弹出层高度（缺省调默认值）
        */
        /*字典-增加*/
        function admin_add(title, url, w, h) {
            var typeid = $("#SelectType").val();
            if (typeid <= 0) {
                parent.layer.alert("请选择字典类型");
            }
            else {
                //url = url + "?" + typeid;
                //alert(url);
                layer_show(title, url + "?" + typeid, w, h);
                
            }
        }

        /*字典-删除*/
        //字典删除根据编号删除字典信息
        function admin_del(id) {
            parent.layer.confirm('确认要删除吗？', function (index) {
                //此处请求后台程序，下方是成功后的前台处理……
                $.ajax({
                    type: "post",
                    url: ApiUrl + "api/Dictionary/Delete",
                    data: {"":id },
                    success: function (data, status) {
                        if (status == "success") {
                            if (data == true) {
                                $("#"+id+"").remove();
                                parent.layer.msg('已删除!', { icon: 1, time: 1000 });
                            }
                            else {
                                parent.layer.msg('删除失败!', { icon: 2, time: 1000 });
                            }
                        }
                    },
                    error: function (e) {
                        parent.layer.msg('网络链接超时...!', { icon: 2, time: 1000 });
                    },
                    complete: function () {

                    }
                })

            });
        }

        /*字典-编辑*/
        function admin_edit(title,url, id, w, h) {
            url=url+"?"+id;
            layer_show(title,url, w, h);
        }

        //根据类型编号查询相关字典信息
        function searchDic()
        {
            var dicType= $("#SelectType").val();
            
            showDic(dicType);
        }

    </script>
</body>
</html>
